package hupu.hnlp.hot_buffer.distbuffer.configuration.job;

import javax.annotation.Resource;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import hupu.hnlp.hot_buffer.distbuffer.appconfig.AppConfig;
import hupu.hnlp.hot_buffer.distbuffer.service.DistBufferService;

@Configuration
@EnableScheduling
class MyScheduleConfiguration
{
    @Resource(name = "appconfig")
    private AppConfig appconfig;

    @Resource
    private DistBufferService dist_buffer_service;

    // 每30秒
    @Scheduled(cron = "0/30 * * * * ?")
    public void syncDowngrade()
    {
        if (dist_buffer_service.canSync())
        {
            dist_buffer_service.syncDowngrade();
        }
    }

    // 每10分钟的10秒 00|10|20...50:30
//    @Scheduled(cron = "10 0/10 * * * ?")
//    public void syncHotListDefault()
//    {
//        if (!appconfig.env.equals("dev"))
//        {
//            if (dist_buffer_service.canSync())
//            {
//                dist_buffer_service.syncHotListDefault();
//            }
//        }
//    }

    // 测试环境：每1分钟的10秒 00|01|02...59:30
//    @Scheduled(cron = "10 0/1 * * * ?")
//    public void syncHotListDefaultDev()
//    {
//        if (appconfig.env.equals("dev"))
//        {
//            if (dist_buffer_service.canSync())
//            {
//                dist_buffer_service.syncHotListDefault();
//            }
//        }
//    }

    // 每10秒
    @Scheduled(fixedDelay = 10 * 1000)
    public void syncBlack()
    {
        if (dist_buffer_service.canSync())
        {
            dist_buffer_service.syncBlack(false);
        }
    }

    // 04:10:20
    @Scheduled(cron = "20 10 4 * * ?")
    public void syncBlackComplete()
    {
        if (dist_buffer_service.canSync())
        {
            dist_buffer_service.syncBlack(true);
        }
    }

    // 每1分钟的30秒 00|01|02...59:40
    @Scheduled(cron = "30 0/1 * * * ?")
    public void syncContent()
    {
        if (dist_buffer_service.canSync())
        {
            dist_buffer_service.syncContent(false);
        }
    }

    // 04:15:30
    @Scheduled(cron = "30 15 4 * * ?")
    public void syncContentComplete()
    {
        if (dist_buffer_service.canSync())
        {
            dist_buffer_service.syncContent(true);
        }
    }

    // 每5分钟的45秒 0|5|10...55:45
    @Scheduled(cron = "45 0/5 * * * ?")
    public void syncVideo()
    {
        if (dist_buffer_service.canSync())
        {
            dist_buffer_service.syncVideo();
        }
    }

    // 每1秒钟
    @Scheduled(fixedDelay = 1 * 1000)
    public void purgeCid()
    {
        dist_buffer_service.purgeCid();
    }

    // 每6秒钟
//    @Scheduled(fixedDelay = 6 * 1000)
//    public void flushCid()
//    {
//        dist_buffer_service.flushCid();
//    }
}
